package com.github.lanif.sys.modular.user.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.lanif.sys.modular.user.entity.SysUserProject;
import com.github.lanif.sys.modular.user.mapper.SysUserProjectMapper;
import com.github.lanif.sys.modular.user.param.SysUserParam;
import com.github.lanif.sys.modular.user.service.SysUserProjectService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 0
 * @date 2020/9/10 18:31
 * @description
 */
@Service
public class SysUserProjectServiceImpl extends ServiceImpl<SysUserProjectMapper, SysUserProject> implements SysUserProjectService {

    @Resource
    private SysUserProjectService sysProjectService;

    @Override
    public List<Long> getUserProjectIdList(Long userId) {
        List<Long> roleIdList = CollectionUtil.newArrayList();
        LambdaQueryWrapper<SysUserProject> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUserProject::getUserId, userId);
        this.list(queryWrapper).forEach(sysUserProject -> roleIdList.add(sysUserProject.getProjectId()));
        return roleIdList;
    }

    @Override
    public void deleteUserProjectListByProjectId(Long roleId) {
        LambdaQueryWrapper<SysUserProject> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUserProject::getProjectId, roleId);
        this.remove(queryWrapper);
    }

    @Override
    public void deleteUserProjectListByUserId(Long userId) {
        LambdaQueryWrapper<SysUserProject> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUserProject::getUserId, userId);
        this.remove(queryWrapper);
    }
}
